<template>
  <div class="beijingtu">
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
      label-width="100px"
      class="demo-ruleForm"
      :label-position="labelPosition"
    >
      <el-card class="box-card" :data="tableData">
        <h1>学生登录</h1>
        <el-form-item label="账号" prop="s_number" class="k1">
          <el-input v-model="form.s_number" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
          placeholder="请输入密码"
          class="k2"
        >
          <el-input
            placeholder="请输入密码"
            v-model="form.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="an1">
          <el-button type="primary" @click="zc">注册</el-button>
        </el-form-item>
        <el-form-item class="an1">
          <el-button type="primary" @click="doselect('form')">登录</el-button>
        </el-form-item>
      </el-card>
    </el-form>
  </div>
</template>

<script>
import { ElMessageBox } from 'element-plus'
const axios = require("axios");
export default {
  name: "xsdl",
  data() {
    return {
      src: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
      radio: [],
      labelPosition: "right",
      tableData: [],
      form: {
        s_number: "",
        password: "",
      },
      rules: {
        //表单验证
        s_number: [
          {
            required: true,
            message: "请输入账号",
            trigger: "blur",
          },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    zc() {
      //跳转对应页面
      this.$router.push({ name: "xszc" });
    },
    doselect(form) {
      //表单验证
      this.$refs[form].validate((valid) => {
        if (valid) {
          let _this = this;
          axios
            .post("https://localhost:44386/api/login/poststudent", {
              s_number: _this.form.s_number,
              password: _this.form.password,
            })
            //当post执行成功后
            .then((response) =>{
              // handle success
              _this.tableData = response.data;
              if (response.data != "") {
                _this.$store.commit("changsnumber", _this.form.s_number);
                _this.sname = _this.$store.state.s_number;
                this.$router.push({ name: "xs" });
              } else {
                ElMessageBox.alert("账号或密码错误 ", "登录", {
                  confirmButtonText: "确认返回",
                });
              }
            });
        } //登录判断
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
body {
  margin: 0;
  padding: 0;
}
.beijingtu {
  background-image: url("1.jpg");
  width: 100%;
  height: 100%;
  background-size: cover;
  position: absolute;
  z-index: -1;
  background-repeat: no-repeat;
}
h1 {
  color: #fff;
}
p {
  margin-top: 80px;
}
.d1 {
  margin-left: 110px;
}
.an1 {
  float: left;
  margin-left: 15px;
}
.k2 {
  width: 400px;
}
.k1 {
  width: 400px;
  margin-bottom: 50px;
}
h1 {
  letter-spacing: 30px;
  text-align: center;
  margin-left: 55px;
}
.box-card {
  width: 500px;
  height: 360px;
  border-radius: 20px;
  margin: 0px auto;
  /* padding-top: 200px; */
  /* margin-top: 300px; */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(61, 124, 160, 0.822);
}
</style>